/* global Module */

/* Magic Mirror
 * Module: MMM-Relay
 *
 * By coffee_java
 * MIT Licensed.
 */

Module.register('MMM-Relay',{

	defaults: {
		sensorPIN: 21,
		powerStatus: true,
		powerOnCron:"0 0 7 * * *",
		powerOffCron:"0 0 23 * * *",
		powerOnState:1
	},

	// Override socket notification handler.
	socketNotificationReceived: function(notification, payload) {
		if(notification === 'POWER_ON'){
			this.config.powerStatus=true;
		}else if(notification === 'POWER_OFF'){
			this.config.powerStatus=false;
		}
	},
	start: function() {
		if (this.config.powerOnState == 1){
			this.config.powerOffState = 0
		}
		else if (this.config.powerOnState == 0){
			this.config.powerOffState = 1
		}
		this.sendSocketNotification('CONFIG', this.config);
		Log.info('Starting module: ' + this.name);
	}
});